﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Text.RegularExpressions;

namespace Acms.Bll.Tests
{
    /// <summary>
    /// Summary description for UnitTest1
    /// </summary>
    [TestClass]
    public class HtmlContentControlTest
    {
        public HtmlContentControlTest()
        {
        }

        [TestMethod]
        public void ReplaceLinkText()
        {
            var html = "<p>[[~/services:test]]blar blar blar [[~/services2:test2]]</p>";

            var regex = new Regex("[[]{2}~/[a-zA-A0-9//-_]{0,}:[a-zA-A0-9//-_]{0,}]{2}");

            var matches = regex.Matches(html);
            Assert.AreEqual(2, matches.Count);
            Assert.AreEqual("[[~/services:test]]", matches[0].Value);
            Assert.AreEqual("[[~/services2:test2]]", matches[1].Value);

            var path = matches[1].Value.Substring(2, matches[1].Value.IndexOf(":") - 2);
            var text = matches[1].Value.Substring(matches[1].Value.IndexOf(":") + 1, matches[1].Value.Length - matches[1].Value.IndexOf(":") - 3);
            Assert.AreEqual("~/services2", path);
            Assert.AreEqual("test2", text);
        }
    }
}
